// ### New Board
var FCKWhiteboardCommand = function()
{
	this.Name = 'Whiteboard' ;
}

FCKWhiteboardCommand.prototype.Execute = function()
{
  parent.open_whiteboard();  //opens the whiteboard to a new blank page  
}

FCKWhiteboardCommand.prototype.GetState = function()
{
	return FCK_TRISTATE_OFF ;
}
// ### Edit Image
var FCKWhiteboardEditorCommand = function()
{
	this.Name = 'Edit Image' ;
}

FCKWhiteboardEditorCommand.prototype.Execute = function()
{
  	
  var oImage = FCK.Selection.GetSelectedElement() ;

  if ( oImage && oImage != null && oImage.tagName == "IMG") {
    var img_class = oImage.className;
    if (img_class.substring(0, 11) == "whiteboard_") {
	    parent.open_whiteboard(img_class.substring(11));  
	} else {    
	    alert("only images created by the whiteboard can be modified");
	}
  } else {
    alert("error: only images may be edited");
  }
}

FCKWhiteboardEditorCommand.prototype.GetState = function()
{
	return FCK_TRISTATE_OFF ;
}


function image_uploaded(img_url, page_number) {
	var oImage = FCK.InsertElement('img');
	oImage.src = img_url;
//	oImage.border = 1;
	oImage.className = "whiteboard_" + page_number;
}



// Register the new whiteboard.
FCKCommands.RegisterCommand( 'Whiteboard' , new FCKWhiteboardCommand()) ;
// Register the "edit image" command
FCKCommands.RegisterCommand( 'Edit Image', new FCKWhiteboardEditorCommand());


// Create the "Whiteboard" toolbar button.
var oWhiteboardItem = new FCKToolbarButton( 'Whiteboard', FCKLang.WhiteboardDlgTitle ) ;
oWhiteboardItem.IconPath = FCKConfig.PluginsPath + 'whiteboard/application_osx.png' ;

FCKToolbarItems.RegisterItem( 'Whiteboard', oWhiteboardItem ) ; // 'My_Find' is the name used in the Toolbar config.

FCK.ContextMenu.RegisterListener( {
        AddItems : function( menu, tag, tagName )
        {
                // under what circumstances do we display this option
                if ( tagName == 'IMG') 	
                {
                        // when the option is displayed, show a separator  the command
                        menu.AddSeparator() ;
                        // the command needs the registered command name, the title for the context menu, and the icon path
                        menu.AddItem( 'Edit Image', FCKLang.WhiteboardDlgTitle, oWhiteboardItem.IconPath ) ;
                }
        }}
);
